﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data.SqlClient;
using System.Data;
using DevExpress.XtraEditors;
using prjKQXS_DLL;
using prjKQXS_DLL.Dal;

namespace prjKQXS_Report.Boc
{
    public partial class rptbienbanboc2 : DevExpress.XtraReports.UI.XtraReport
    {
        public rptbienbanboc2()
        {
            InitializeComponent();
        }

        private void rptbienbanboc2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Report_DAL report_dal = new Report_DAL();
            lblngay.Text = BienTc.denngay.Day.ToString();
            lblthang.Text = BienTc.denngay.Month.ToString();
            lblnam.Text = BienTc.denngay.Year.ToString();
            dsReports1 = report_dal.reportDungChung(dsReports1);
            dsReports1 = xuly(dsReports1);
        }
string kyhieu = BienTc.KyHieuVe;
        DateTime ngay = BienTc.denngay;
        dsReports ds = new dsReports();
        SqlConnection conn = new SqlConnection(BienTc.connString);
        private dsReports xuly(dsReports ds)
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlDataAdapter da = null;
            SqlDataAdapter da1 = null;
            da1 = new SqlDataAdapter("Select * from KETQUATT where Convert(Datetime,Ngaymothuong,103) = Convert(Datetime,@Ngay,103)", conn);
            da1.SelectCommand.Parameters.AddWithValue("@Ngay", ngay);
            DataTable dtl = new DataTable();
            da1.Fill(dtl);
            foreach (DataRow rowCB in dtl.Rows)
            {
                DataRow rowC = dsReports1.Hoidongtt.NewRow();
                rowC["Phochutich"] = rowCB["Pchutich"];
                rowC["Congty"] = rowCB["Congty"];
                rowC["Sotuphap"] = rowCB["Sotuphap"];
                rowC["Sotaichinh"] = rowCB["Sotaichinh"];
                rowC["Congantinh"] = rowCB["Congantinh"];
                rowC["Mattrantq"] = rowCB["Mattrantq"];
                rowC["Thanhtrann"] = rowCB["Thanhtrann"];
                rowC["Thuky"] = rowCB["Thuky"];
                dsReports1.Hoidongtt.Rows.Add(rowC);
            }
            da = new SqlDataAdapter("Select * from Ketquaveboc2 Where Kyhieu = @kyhieu", conn);
            da.SelectCommand.Parameters.AddWithValue("@kyhieu", kyhieu);
            DataTable dt = new DataTable();
            da.Fill(dt);
            foreach (DataRow rowCB in dt.Rows)
            {
                DataRow rowC = dsReports1.Ketquaveboc2.NewRow();
                rowC["Ngayquayso"] = rowCB["Ngayquayso"];
                rowC["Kyhieu"] = rowCB["Kyhieu"];
                rowC["Giave"] = rowCB["Giave"];
                rowC["gnhat1"] = rowCB["gnhat1"];
                rowC["gnhat2"] = rowCB["gnhat2"];
                rowC["gnhat3"] = rowCB["gnhat3"];
                rowC["gnhat4"] = rowCB["gnhat4"];
                rowC["gnhi1"] = rowCB["gnhi1"];
                rowC["gba1"] = rowCB["gba1"];
                rowC["gtu1"] = rowCB["gtu1"];
                rowC["gtu2"] = rowCB["gtu2"];
                rowC["gnam1"] = rowCB["gnam1"];
                rowC["gnam2"] = rowCB["gnam2"];
                rowC["gnam3"] = rowCB["gnam3"];
                rowC["gnam4"] = rowCB["gnam4"];
                rowC["gnam5"] = rowCB["gnam5"];
                rowC["gnam6"] = rowCB["gnam6"];
                rowC["gnam7"] = rowCB["gnam7"];
                rowC["gnam8"] = rowCB["gnam8"];
                rowC["gnam9"] = rowCB["gnam9"];
                rowC["gnam10"] = rowCB["gnam10"];
                rowC["gnam11"] = rowCB["gnam11"];
                rowC["gnam12"] = rowCB["gnam12"];
                rowC["gnam13"] = rowCB["gnam13"];
                rowC["gnam14"] = rowCB["gnam14"];
                rowC["gnam15"] = rowCB["gnam15"];
                rowC["gnam16"] = rowCB["gnam16"];
                rowC["gnam17"] = rowCB["gnam17"];
                rowC["gnam18"] = rowCB["gnam18"];
                dsReports1.Ketquaveboc2.Rows.Add(rowC);
            }
            return ds;
        } 
    }
}

